//
//  RetryNet.swift
//  todoios
//
//  Created by qianli on 2025/4/16.
//

import Foundation
import UIKit


class RetryNet: UIView {
    private var dyIR1rQ3byinBhkP:UILabel?
    private var WSt16jx438XdhHZ4:UIImageView?
    var tapBlock: os_block_t?
    
    deinit {
        QianliUniversalFunc.QianliLog("------RetryNet.deinit")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        GHL4Rhb91XYBer27()
    }
    
//    init(frame:CGRect,title:String){
//        super.init(frame: frame)
//        self.GHL4Rhb91XYBer27(title)
//    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func GHL4Rhb91XYBer27(){
        self.backgroundColor = .secondarySystemBackground
        self.WSt16jx438XdhHZ4 = UIImageView(frame: CGRect(x: self.bounds.width/2 - 159/2, y: self.bounds.height/2 - 128 - 80, width: 159, height: 128))
        if let imgview = self.WSt16jx438XdhHZ4{
            self.addSubview(imgview)
            imgview.image = "qianli_errdata".qianli_R_image //318*256(2x)
            
            self.dyIR1rQ3byinBhkP = UILabel(frame: CGRect(x: 15, y: imgview.frame.maxY+15, width: self.bounds.width-30, height: 20))
            if let label = self.dyIR1rQ3byinBhkP{
                self.addSubview(label)
                label.font = .systemFont(ofSize: 16)
                label.textColor = .secondaryLabel
                label.textAlignment = .center
                
                let button = UIButton(frame: CGRect(x: self.bounds.width/2 - 160/2, y: label.frame.maxY + 40, width: 160, height: 42))
                self.addSubview(button)
                button.setTitle("点击重试", for: .normal)
                button.backgroundColor = UIColor(245, 249, 255)
                button.titleLabel?.font = .systemFont(ofSize: 16)
                button.setTitleColor(UIColor(hexString: "#3964ff"), for: .normal)
                button.layer.cornerRadius = 21
                button.touch_With_Block { [weak self](sender) in
                    self?.tapBlock?()
                }
            }
        }
        
    }
    
    func vSXenwySp9gyesbp(_ msg:String){
        self.dyIR1rQ3byinBhkP?.text = msg
    }
    
    func d770kqK5BHcHWehm(_ iType :Int = 0){
//iType=0表示请求失败，=1表示请求数据为空
        if let imgview = self.WSt16jx438XdhHZ4{
            if (0==iType){
                imgview.image = "qianli_errdata".qianli_R_image
            }else{
                imgview.image = "qianli_nulldata".qianli_R_image
            }
        }
    }
}
